<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="品牌" prop="supplierId">
									<el-input v-model="form.supplierId" placeholder="请输入品牌" clearable></el-input>
								</el-form-item>
								<el-form-item label="企业" prop="departmentId">
									<el-input v-model="form.departmentId" placeholder="请输入企业" clearable></el-input>
								</el-form-item>
								<el-form-item label="分类" prop="supplierTypeId">
									<el-input v-model="form.supplierTypeId" placeholder="请输入分类" clearable></el-input>
								</el-form-item>
								<el-form-item label="主营栏目" prop="catorgoryName">
									<el-input v-model="form.catorgoryName" placeholder="请输入主营栏目" clearable></el-input>
								</el-form-item>
								<el-form-item label="名称" prop="name">
									<el-input v-model="form.name" placeholder="请输入名称" clearable></el-input>
								</el-form-item>
								<el-form-item label="拼音" prop="pinyin">
									<el-input v-model="form.pinyin" placeholder="请输入拼音" clearable></el-input>
								</el-form-item>
								<el-form-item label="联系人" prop="linkUser">
									<el-input v-model="form.linkUser" placeholder="请输入联系人" clearable></el-input>
								</el-form-item>
								<el-form-item label="联系电话" prop="linkTel">
									<el-input v-model="form.linkTel" placeholder="请输入联系电话" clearable></el-input>
								</el-form-item>
								<el-form-item label="区域" prop="regionPath">
									<el-input v-model="form.regionPath" placeholder="请输入区域" clearable></el-input>
								</el-form-item>
								<el-form-item label="地址" prop="address">
									<el-input v-model="form.address" placeholder="请输入地址" clearable></el-input>
								</el-form-item>
								<el-form-item label="手机" prop="phone">
									<el-input v-model="form.phone" placeholder="请输入手机" clearable></el-input>
								</el-form-item>
								<el-form-item label="微信" prop="wechat">
									<el-input v-model="form.wechat" placeholder="请输入微信" clearable></el-input>
								</el-form-item>
								<el-form-item label="邮箱" prop="email">
									<el-input v-model="form.email" placeholder="请输入邮箱" clearable></el-input>
								</el-form-item>
								<el-form-item label="官网" prop="webHome">
									<el-input v-model="form.webHome" placeholder="请输入官网" clearable></el-input>
								</el-form-item>
								<el-form-item label="需支付" prop="needPay">
									<el-input v-model="form.needPay" placeholder="请输入需支付" clearable></el-input>
								</el-form-item>
								<el-form-item label="开户名称" prop="accountName">
									<el-input v-model="form.accountName" placeholder="请输入开户名称" clearable></el-input>
								</el-form-item>
								<el-form-item label="纳税人识别号" prop="accountCode">
									<el-input v-model="form.accountCode" placeholder="请输入纳税人识别号" clearable></el-input>
								</el-form-item>
								<el-form-item label="开户银行的名称" prop="bankName">
									<el-input v-model="form.bankName" placeholder="请输入开户银行的名称" clearable></el-input>
								</el-form-item>
								<el-form-item label="银行账号" prop="bankAccount">
									<el-input v-model="form.bankAccount" placeholder="请输入银行账号" clearable></el-input>
								</el-form-item>
								<el-form-item label="1现结 2欠款 3当月结 4次月结" prop="payType">
									<el-input v-model="form.payType" placeholder="请输入1现结 2欠款 3当月结 4次月结" clearable></el-input>
								</el-form-item>
								<el-form-item label="付款期限?天" prop="payDay">
									<el-input v-model="form.payDay" placeholder="请输入付款期限?天" clearable></el-input>
								</el-form-item>
								<el-form-item label="排序" prop="seq">
									<el-input v-model="form.seq" placeholder="请输入排序" clearable></el-input>
								</el-form-item>
								<el-form-item label="是否默认" prop="isDefault">
									<el-input v-model="form.isDefault" placeholder="请输入是否默认" clearable></el-input>
								</el-form-item>
								<el-form-item label="1激活 0停用" prop="status">
									<el-input v-model="form.status" placeholder="请输入1激活 0停用" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	import purchaseAPI from '@/api/purchase/supplier';
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: ''
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					supplierId: "",
					departmentId: "",
					supplierTypeId: "",
					catorgoryName: "",
					name: "",
					pinyin: "",
					linkUser: "",
					linkTel: "",
					regionPath: "",
					address: "",
					phone: "",
					wechat: "",
					email: "",
					webHome: "",
					needPay: "",
					accountName: "",
					accountCode: "",
					bankName: "",
					bankAccount: "",
					payType: "",
					payDay: "",
					seq: "",
					isDefault: "",
					status: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await purchaseAPI.supplier.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.supplierId = data.supplierId;
				this.form.departmentId = data.departmentId;
				this.form.supplierTypeId = data.supplierTypeId;
				this.form.catorgoryName = data.catorgoryName;
				this.form.name = data.name;
				this.form.pinyin = data.pinyin;
				this.form.linkUser = data.linkUser;
				this.form.linkTel = data.linkTel;
				this.form.regionPath = data.regionPath;
				this.form.address = data.address;
				this.form.phone = data.phone;
				this.form.wechat = data.wechat;
				this.form.email = data.email;
				this.form.webHome = data.webHome;
				this.form.needPay = data.needPay;
				this.form.accountName = data.accountName;
				this.form.accountCode = data.accountCode;
				this.form.bankName = data.bankName;
				this.form.bankAccount = data.bankAccount;
				this.form.payType = data.payType;
				this.form.payDay = data.payDay;
				this.form.seq = data.seq;
				this.form.isDefault = data.isDefault;
				this.form.status = data.status;
			}
		}
	}
</script>
<style>
</style>
